<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/saiki.jpeg?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/saiki.jpeg?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Java,python,">










<meta name="description" content="1.循环Java  5ms123456789public static void main(String[] args) &amp;#123;      long t1 = System.currentTimeMillis();      int count = 0;      for (int i = 0; i &amp;lt; 100000000; i++) &amp;#123;      &amp;#125;      l">
<meta name="keywords" content="Java,python">
<meta property="og:type" content="article">
<meta property="og:title" content="Java Python 速度对比">
<meta property="og:url" content="http://yoursite.com/2019/05/28/Java Python 速度对比/index.html">
<meta property="og:site_name" content="Penn">
<meta property="og:description" content="1.循环Java  5ms123456789public static void main(String[] args) &amp;#123;      long t1 = System.currentTimeMillis();      int count = 0;      for (int i = 0; i &amp;lt; 100000000; i++) &amp;#123;      &amp;#125;      l">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-05-28T03:57:49.257Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java Python 速度对比">
<meta name="twitter:description" content="1.循环Java  5ms123456789public static void main(String[] args) &amp;#123;      long t1 = System.currentTimeMillis();      int count = 0;      for (int i = 0; i &amp;lt; 100000000; i++) &amp;#123;      &amp;#125;      l">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":true},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/05/28/Java Python 速度对比/">





  <title>Java Python 速度对比 | Penn</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Penn</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">my blog</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-schedule">
          <a href="/schedule/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-calendar"></i> <br>
            
            日程表
          </a>
        </li>
      
        
        <li class="menu-item menu-item-sitemap">
          <a href="/sitemap.xml" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-sitemap"></i> <br>
            
            站点地图
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br>
            
            公益404
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/05/28/Java Python 速度对比/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Shen">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/saiki.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Penn">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Java Python 速度对比</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-05-28T11:57:49+08:00">
                2019-05-28
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="/categories/技术/" itemprop="url" rel="index">
                    <span itemprop="name">技术</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2019/05/28/Java Python 速度对比/" class="leancloud_visitors" data-flag-title="Java Python 速度对比">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="1-循环"><a href="#1-循环" class="headerlink" title="1.循环"></a>1.循环</h3><p>Java  5ms<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">public static void main(String[] args) &#123;</span><br><span class="line">      long t1 = System.currentTimeMillis();</span><br><span class="line">      int count = 0;</span><br><span class="line">      for (int i = 0; i &lt; 100000000; i++) &#123;</span><br><span class="line"></span><br><span class="line">      &#125;</span><br><span class="line">      long t2 = System.currentTimeMillis();</span><br><span class="line">      System.out.println(t2 - t1);</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure></p>
<p>python  12553ms<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">while i &lt;100000000:</span><br><span class="line">	i=i+1</span><br><span class="line">end = int(round(1000*time.time()))</span><br></pre></td></tr></table></figure></p>
<p>python循环特别慢</p>
<hr>
<h3 id="2-循环处理字符串-循环次数少个0"><a href="#2-循环处理字符串-循环次数少个0" class="headerlink" title="2.循环处理字符串(循环次数少个0)"></a>2.循环处理字符串(循环次数少个0)</h3><p>Java 21193ms<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">String str = &quot;20492\tgame1\t3\tgame1#20492_3\t120\t0\t10.2.178.137\t10.13.4\t24013\t\t\t&#123;\&quot;data\&quot;:&#123;\&quot;rewardList\&quot;:[&#123;\&quot;amount\&quot;:5,\&quot;code\&quot;:\&quot;1\&quot;,\&quot;currencyType\&quot;:\&quot;DIAMOND\&quot;,\&quot;subType\&quot;:0,\&quot;tag\&quot;:\&quot;DIAMOND\&quot;,\&quot;type\&quot;:\&quot;CURRENCY\&quot;,\&quot;typeValue\&quot;:1&#125;,&#123;\&quot;amount\&quot;:1,\&quot;code\&quot;:\&quot;it_220001\&quot;,\&quot;itemConfigId\&quot;:\&quot;it_220001\&quot;,\&quot;limit\&quot;:0,\&quot;tag\&quot;:\&quot;it_220001\&quot;,\&quot;type\&quot;:\&quot;ITEM\&quot;,\&quot;typeValue\&quot;:2&#125;,&#123;\&quot;amount\&quot;:1,\&quot;code\&quot;:\&quot;it_209101\&quot;,\&quot;itemConfigId\&quot;:\&quot;it_209101\&quot;,\&quot;limit\&quot;:0,\&quot;tag\&quot;:\&quot;it_209101\&quot;,\&quot;type\&quot;:\&quot;ITEM\&quot;,\&quot;typeValue\&quot;:2&#125;]&#125;,\&quot;name\&quot;:\&quot;6ZKp6ZWw6Zy45Li75LmU5qOu\&quot;,\&quot;action\&quot;:\&quot;TeamBattleHandler.endBattle\&quot;,\&quot;client\&quot;:&#123;\&quot;isEscape\&quot;:0,\&quot;battleData\&quot;:&#123;\&quot;blockId\&quot;:\&quot;team_001\&quot;,\&quot;scriptVersion\&quot;:\&quot;dev_3\&quot;,\&quot;operate\&quot;:&#123;\&quot;myOps\&quot;:[[[&#123;\&quot;a\&quot;:[\&quot;f1\&quot;,\&quot;e5\&quot;],\&quot;c\&quot;:1&#125;,&#123;\&quot;a\&quot;:[3,\&quot;f1\&quot;],\&quot;c\&quot;:2&#125;],[&#123;\&quot;a\&quot;:[\&quot;f1\&quot;,\&quot;e5\&quot;],\&quot;c\&quot;:1&#125;]]],\&quot;enemyOps\&quot;:[[[&#123;\&quot;a\&quot;:[\&quot;e5\&quot;,\&quot;f1\&quot;],\&quot;c\&quot;:1&#125;,&#123;\&quot;a\&quot;:[3,\&quot;e5\&quot;],\&quot;c\&quot;:2&#125;]]]&#125;,\&quot;enemyInfo\&quot;:&#123;\&quot;monsterId\&quot;:\&quot;team_001\&quot;,\&quot;hero\&quot;:&#123;\&quot;5\&quot;:&#123;\&quot;bss\&quot;:&#123;&#125;,\&quot;blockdeepen\&quot;:0.5,\&quot;angerbase\&quot;:1,\&quot;hp\&quot;:12218.0,\&quot;cure\&quot;:1.0,\&quot;dp\&quot;:[\&quot;sk_heroNormal_sp\&quot;],\&quot;uuid\&quot;:\&quot;9F5rOHXh\&quot;,\&quot;anger\&quot;:1,\&quot;speed\&quot;:1.0,\&quot;unhurt\&quot;:0.0,\&quot;drain\&quot;:0.0,\&quot;uncrit\&quot;:0.0,\&quot;unblock\&quot;:0.0,\&quot;dataId\&quot;:\&quot;he_100001\&quot;,\&quot;effecthit\&quot;:0.0,\&quot;defense\&quot;:0.0,\&quot;attack\&quot;:757.0,\&quot;skill\&quot;:&#123;\&quot;1\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_n\&quot;&#125;,\&quot;2\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_f\&quot;&#125;&#125;,\&quot;skillhurt\&quot;:0.0,\&quot;block\&quot;:0.05,\&quot;id\&quot;:\&quot;he_100001\&quot;,\&quot;angerMax\&quot;:2,\&quot;antihurt\&quot;:0.0,\&quot;sp\&quot;:&#123;&#125;,\&quot;critdeepen\&quot;:1.5,\&quot;star\&quot;:1,\&quot;level\&quot;:31,\&quot;dotunhurt\&quot;:0.0,\&quot;speeduprate\&quot;:0.0,\&quot;effectdodge\&quot;:0.0,\&quot;quality\&quot;:31,\&quot;crit\&quot;:0.05,\&quot;dothurt\&quot;:0.0,\&quot;defrate\&quot;:1.0,\&quot;hurt\&quot;:0.0,\&quot;atkrate\&quot;:1.0,\&quot;skillunhurt\&quot;:0.0&#125;&#125;&#125;,\&quot;dataVersion\&quot;:\&quot;dev_3\&quot;,\&quot;randomseed\&quot;:781938,\&quot;myInfo\&quot;:&#123;\&quot;hero\&quot;:&#123;\&quot;1\&quot;:&#123;\&quot;bss\&quot;:&#123;&#125;,\&quot;blockdeepen\&quot;:0.5,\&quot;hp\&quot;:44054.0,\&quot;fp\&quot;:&#123;&#125;,\&quot;cure\&quot;:1.0,\&quot;dp\&quot;:[\&quot;sk_heroNormal_sp\&quot;],\&quot;uuid\&quot;:\&quot;Ql4JTCrg\&quot;,\&quot;speed\&quot;:87.0,\&quot;unhurt\&quot;:0.0,\&quot;drain\&quot;:0.0,\&quot;uncrit\&quot;:0.0,\&quot;unblock\&quot;:0.0,\&quot;effecthit\&quot;:0.0,\&quot;defense\&quot;:1796.0,\&quot;attack\&quot;:7442.0,\&quot;rankLevel\&quot;:1,\&quot;skill\&quot;:&#123;\&quot;1\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_n\&quot;&#125;,\&quot;2\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_f\&quot;&#125;,\&quot;3\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_pp\&quot;&#125;&#125;,\&quot;talent\&quot;:&#123;\&quot;1\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_starUnlock_1\&quot;&#125;,\&quot;2\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_starUnlock_3\&quot;&#125;,\&quot;3\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_starUnlock_4\&quot;&#125;&#125;,\&quot;skillhurt\&quot;:0.0,\&quot;block\&quot;:0.05,\&quot;id\&quot;:\&quot;he_100001\&quot;,\&quot;antihurt\&quot;:0.0,\&quot;sp\&quot;:&#123;&#125;,\&quot;critdeepen\&quot;:1.5,\&quot;star\&quot;:5,\&quot;level\&quot;:120,\&quot;dotunhurt\&quot;:0.0,\&quot;speeduprate\&quot;:0.0,\&quot;ep\&quot;:[],\&quot;effectdodge\&quot;:0.0,\&quot;quality\&quot;:40,\&quot;crit\&quot;:0.17,\&quot;dothurt\&quot;:0.0,\&quot;defrate\&quot;:1.0,\&quot;hurt\&quot;:0.0,\&quot;atkrate\&quot;:1.0,\&quot;skillunhurt\&quot;:0.0&#125;&#125;&#125;&#125;,\&quot;monsterId\&quot;:\&quot;team_001\&quot;,\&quot;isWin\&quot;:true&#125;,\&quot;diff\&quot;:&#123;\&quot;wallet\&quot;:&#123;\&quot;moneys\&quot;:&#123;\&quot;diamond\&quot;:&#123;\&quot;amount\&quot;:10001035&#125;,\&quot;challengevolume\&quot;:&#123;\&quot;amount\&quot;:2&#125;&#125;&#125;,\&quot;teamBattleInfo\&quot;:&#123;\&quot;battle\&quot;:false,\&quot;monsters\&quot;:&#123;&#125;,\&quot;battleCount\&quot;:1&#125;,\&quot;record\&quot;:&#123;\&quot;map\&quot;:&#123;\&quot;2008\&quot;:1,\&quot;2016\&quot;:1,\&quot;2025\&quot;:1,\&quot;1010\&quot;:10001055&#125;&#125;,\&quot;itemBag\&quot;:&#123;\&quot;items\&quot;:&#123;\&quot;it_209101\&quot;:&#123;\&quot;amount\&quot;:5002&#125;,\&quot;it_220001\&quot;:&#123;\&quot;amount\&quot;:4810&#125;&#125;&#125;,\&quot;lastRefreshTime\&quot;:1546839201057,\&quot;taskProgress\&quot;:&#123;\&quot;workingTasks\&quot;:&#123;\&quot;Daily_TeamBattleComplete\&quot;:&#123;\&quot;cv\&quot;:1,\&quot;s\&quot;:\&quot;FINISH_NOT_DRAW\&quot;&#125;&#125;&#125;&#125;,\&quot;time\&quot;:\&quot;2019-01-07 13:33:21\&quot;&#125;\tD1497C49EC4756B78E0E1AD0DBFC6E83\t1546839201&quot;;</span><br><span class="line">        for (int i = 0; i &lt; 10000000; i++) &#123;</span><br><span class="line">            if (str.contains(&quot;it_220001&quot;)) &#123;</span><br><span class="line">                int index = str.indexOf(&quot;speeduprate&quot;);</span><br><span class="line">                String str2 = str.substring(index, index + 10);</span><br><span class="line">            &#125;</span><br><span class="line">            if (str.contains(&quot;_220001&quot;)) &#123;</span><br><span class="line">                int index = str.indexOf(&quot;speeduprate&quot;);</span><br><span class="line">                String str2 = str.substring(index, index + 10);</span><br><span class="line">            &#125;</span><br><span class="line">            if (str.contains(&quot;t_220001&quot;)) &#123;</span><br><span class="line">                int index = str.indexOf(&quot;speeduprate&quot;);</span><br><span class="line">                String str2 = str.substring(index, index + 10);</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br></pre></td></tr></table></figure></p>
<p>python 41043ms<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">strs = &quot;20492\tgame1\t3\tgame1#20492_3\t120\t0\t10.2.178.137\t10.13.4\t24013\t\t\t&#123;\&quot;data\&quot;:&#123;\&quot;rewardList\&quot;:[&#123;\&quot;amount\&quot;:5,\&quot;code\&quot;:\&quot;1\&quot;,\&quot;currencyType\&quot;:\&quot;DIAMOND\&quot;,\&quot;subType\&quot;:0,\&quot;tag\&quot;:\&quot;DIAMOND\&quot;,\&quot;type\&quot;:\&quot;CURRENCY\&quot;,\&quot;typeValue\&quot;:1&#125;,&#123;\&quot;amount\&quot;:1,\&quot;code\&quot;:\&quot;it_220001\&quot;,\&quot;itemConfigId\&quot;:\&quot;it_220001\&quot;,\&quot;limit\&quot;:0,\&quot;tag\&quot;:\&quot;it_220001\&quot;,\&quot;type\&quot;:\&quot;ITEM\&quot;,\&quot;typeValue\&quot;:2&#125;,&#123;\&quot;amount\&quot;:1,\&quot;code\&quot;:\&quot;it_209101\&quot;,\&quot;itemConfigId\&quot;:\&quot;it_209101\&quot;,\&quot;limit\&quot;:0,\&quot;tag\&quot;:\&quot;it_209101\&quot;,\&quot;type\&quot;:\&quot;ITEM\&quot;,\&quot;typeValue\&quot;:2&#125;]&#125;,\&quot;name\&quot;:\&quot;6ZKp6ZWw6Zy45Li75LmU5qOu\&quot;,\&quot;action\&quot;:\&quot;TeamBattleHandler.endBattle\&quot;,\&quot;client\&quot;:&#123;\&quot;isEscape\&quot;:0,\&quot;battleData\&quot;:&#123;\&quot;blockId\&quot;:\&quot;team_001\&quot;,\&quot;scriptVersion\&quot;:\&quot;dev_3\&quot;,\&quot;operate\&quot;:&#123;\&quot;myOps\&quot;:[[[&#123;\&quot;a\&quot;:[\&quot;f1\&quot;,\&quot;e5\&quot;],\&quot;c\&quot;:1&#125;,&#123;\&quot;a\&quot;:[3,\&quot;f1\&quot;],\&quot;c\&quot;:2&#125;],[&#123;\&quot;a\&quot;:[\&quot;f1\&quot;,\&quot;e5\&quot;],\&quot;c\&quot;:1&#125;]]],\&quot;enemyOps\&quot;:[[[&#123;\&quot;a\&quot;:[\&quot;e5\&quot;,\&quot;f1\&quot;],\&quot;c\&quot;:1&#125;,&#123;\&quot;a\&quot;:[3,\&quot;e5\&quot;],\&quot;c\&quot;:2&#125;]]]&#125;,\&quot;enemyInfo\&quot;:&#123;\&quot;monsterId\&quot;:\&quot;team_001\&quot;,\&quot;hero\&quot;:&#123;\&quot;5\&quot;:&#123;\&quot;bss\&quot;:&#123;&#125;,\&quot;blockdeepen\&quot;:0.5,\&quot;angerbase\&quot;:1,\&quot;hp\&quot;:12218.0,\&quot;cure\&quot;:1.0,\&quot;dp\&quot;:[\&quot;sk_heroNormal_sp\&quot;],\&quot;uuid\&quot;:\&quot;9F5rOHXh\&quot;,\&quot;anger\&quot;:1,\&quot;speed\&quot;:1.0,\&quot;unhurt\&quot;:0.0,\&quot;drain\&quot;:0.0,\&quot;uncrit\&quot;:0.0,\&quot;unblock\&quot;:0.0,\&quot;dataId\&quot;:\&quot;he_100001\&quot;,\&quot;effecthit\&quot;:0.0,\&quot;defense\&quot;:0.0,\&quot;attack\&quot;:757.0,\&quot;skill\&quot;:&#123;\&quot;1\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_n\&quot;&#125;,\&quot;2\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_f\&quot;&#125;&#125;,\&quot;skillhurt\&quot;:0.0,\&quot;block\&quot;:0.05,\&quot;id\&quot;:\&quot;he_100001\&quot;,\&quot;angerMax\&quot;:2,\&quot;antihurt\&quot;:0.0,\&quot;sp\&quot;:&#123;&#125;,\&quot;critdeepen\&quot;:1.5,\&quot;star\&quot;:1,\&quot;level\&quot;:31,\&quot;dotunhurt\&quot;:0.0,\&quot;speeduprate\&quot;:0.0,\&quot;effectdodge\&quot;:0.0,\&quot;quality\&quot;:31,\&quot;crit\&quot;:0.05,\&quot;dothurt\&quot;:0.0,\&quot;defrate\&quot;:1.0,\&quot;hurt\&quot;:0.0,\&quot;atkrate\&quot;:1.0,\&quot;skillunhurt\&quot;:0.0&#125;&#125;&#125;,\&quot;dataVersion\&quot;:\&quot;dev_3\&quot;,\&quot;randomseed\&quot;:781938,\&quot;myInfo\&quot;:&#123;\&quot;hero\&quot;:&#123;\&quot;1\&quot;:&#123;\&quot;bss\&quot;:&#123;&#125;,\&quot;blockdeepen\&quot;:0.5,\&quot;hp\&quot;:44054.0,\&quot;fp\&quot;:&#123;&#125;,\&quot;cure\&quot;:1.0,\&quot;dp\&quot;:[\&quot;sk_heroNormal_sp\&quot;],\&quot;uuid\&quot;:\&quot;Ql4JTCrg\&quot;,\&quot;speed\&quot;:87.0,\&quot;unhurt\&quot;:0.0,\&quot;drain\&quot;:0.0,\&quot;uncrit\&quot;:0.0,\&quot;unblock\&quot;:0.0,\&quot;effecthit\&quot;:0.0,\&quot;defense\&quot;:1796.0,\&quot;attack\&quot;:7442.0,\&quot;rankLevel\&quot;:1,\&quot;skill\&quot;:&#123;\&quot;1\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_n\&quot;&#125;,\&quot;2\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_f\&quot;&#125;,\&quot;3\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_pp\&quot;&#125;&#125;,\&quot;talent\&quot;:&#123;\&quot;1\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_starUnlock_1\&quot;&#125;,\&quot;2\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_starUnlock_3\&quot;&#125;,\&quot;3\&quot;:&#123;\&quot;level\&quot;:1,\&quot;id\&quot;:\&quot;sk_hero001_starUnlock_4\&quot;&#125;&#125;,\&quot;skillhurt\&quot;:0.0,\&quot;block\&quot;:0.05,\&quot;id\&quot;:\&quot;he_100001\&quot;,\&quot;antihurt\&quot;:0.0,\&quot;sp\&quot;:&#123;&#125;,\&quot;critdeepen\&quot;:1.5,\&quot;star\&quot;:5,\&quot;level\&quot;:120,\&quot;dotunhurt\&quot;:0.0,\&quot;speeduprate\&quot;:0.0,\&quot;ep\&quot;:[],\&quot;effectdodge\&quot;:0.0,\&quot;quality\&quot;:40,\&quot;crit\&quot;:0.17,\&quot;dothurt\&quot;:0.0,\&quot;defrate\&quot;:1.0,\&quot;hurt\&quot;:0.0,\&quot;atkrate\&quot;:1.0,\&quot;skillunhurt\&quot;:0.0&#125;&#125;&#125;&#125;,\&quot;monsterId\&quot;:\&quot;team_001\&quot;,\&quot;isWin\&quot;:true&#125;,\&quot;diff\&quot;:&#123;\&quot;wallet\&quot;:&#123;\&quot;moneys\&quot;:&#123;\&quot;diamond\&quot;:&#123;\&quot;amount\&quot;:10001035&#125;,\&quot;challengevolume\&quot;:&#123;\&quot;amount\&quot;:2&#125;&#125;&#125;,\&quot;teamBattleInfo\&quot;:&#123;\&quot;battle\&quot;:false,\&quot;monsters\&quot;:&#123;&#125;,\&quot;battleCount\&quot;:1&#125;,\&quot;record\&quot;:&#123;\&quot;map\&quot;:&#123;\&quot;2008\&quot;:1,\&quot;2016\&quot;:1,\&quot;2025\&quot;:1,\&quot;1010\&quot;:10001055&#125;&#125;,\&quot;itemBag\&quot;:&#123;\&quot;items\&quot;:&#123;\&quot;it_209101\&quot;:&#123;\&quot;amount\&quot;:5002&#125;,\&quot;it_220001\&quot;:&#123;\&quot;amount\&quot;:4810&#125;&#125;&#125;,\&quot;lastRefreshTime\&quot;:1546839201057,\&quot;taskProgress\&quot;:&#123;\&quot;workingTasks\&quot;:&#123;\&quot;Daily_TeamBattleComplete\&quot;:&#123;\&quot;cv\&quot;:1,\&quot;s\&quot;:\&quot;FINISH_NOT_DRAW\&quot;&#125;&#125;&#125;&#125;,\&quot;time\&quot;:\&quot;2019-01-07 13:33:21\&quot;&#125;\tD1497C49EC4756B78E0E1AD0DBFC6E83\t1546839201&quot;; </span><br><span class="line">i=0</span><br><span class="line">while i &lt;10000000:</span><br><span class="line">	i=i+1</span><br><span class="line">	if &apos;it_220001&apos; in strs:</span><br><span class="line">		index = strs.find(&apos;speeduprate&apos;)</span><br><span class="line">		str2 = strs[index:index+10]</span><br><span class="line">	if &apos;_220001&apos; in strs:</span><br><span class="line">		index = strs.find(&apos;speeduprate&apos;)</span><br><span class="line">		str2 = strs[index:index+10]</span><br><span class="line">	if &apos;t_220001&apos; in strs:</span><br><span class="line">		index = strs.find(&apos;speeduprate&apos;)</span><br><span class="line">		str2 = strs[index:index+10]</span><br></pre></td></tr></table></figure></p>
<p>python 字符串处理比java快特别多</p>
<hr>
<h3 id="3-读取文件"><a href="#3-读取文件" class="headerlink" title="3.读取文件"></a>3.读取文件</h3><p>Java 228707<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">String path = &quot;/Volumes/macwin/action日志/action_log_2018-12-05.log&quot;;</span><br><span class="line">        long t1 = System.currentTimeMillis();</span><br><span class="line">        String str;</span><br><span class="line">        BufferedReader br = new BufferedReader(new FileReader(path));</span><br><span class="line">        while ((str = br.readLine()) != null) &#123;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br></pre></td></tr></table></figure></p>
<p>python 228838<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">path = &quot;/Volumes/macwin/action日志/action_log_2018-12-05.log&quot;</span><br><span class="line">with open(path,&apos;r&apos;) as f:</span><br><span class="line">	for line in f:</span><br><span class="line">		pass</span><br></pre></td></tr></table></figure></p>
<hr>
<h3 id="4-NIO-MappedBuffer"><a href="#4-NIO-MappedBuffer" class="headerlink" title="4.NIO MappedBuffer"></a>4.NIO MappedBuffer</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line">private static final int LEN = 2047483646;</span><br><span class="line"></span><br><span class="line"> public static void main(String[] args) &#123;</span><br><span class="line">     int line = 0;</span><br><span class="line">     try &#123;</span><br><span class="line"></span><br><span class="line">         FileChannel fc = new FileInputStream(path).getChannel();</span><br><span class="line"></span><br><span class="line">         BufferedWriter bw = new BufferedWriter(new FileWriter(path2));</span><br><span class="line">         long t1 = System.currentTimeMillis();</span><br><span class="line">         byte[] bs;</span><br><span class="line">         byte[] temp = new byte[0];</span><br><span class="line">         String str;</span><br><span class="line">         Map&lt;String, Integer&gt; map = Maps.newHashMap();</span><br><span class="line"></span><br><span class="line">         long prePos = 0;</span><br><span class="line"></span><br><span class="line">         int count = (int) (fc.size() / LEN + 1);</span><br><span class="line">         int offset = LEN;</span><br><span class="line">         long size = fc.size();</span><br><span class="line"></span><br><span class="line">         for (int c = 0; c &lt; count; c++) &#123;</span><br><span class="line">             prePos += offset;</span><br><span class="line">             if (size - prePos &lt; LEN) &#123;</span><br><span class="line">                 offset = (int) (size - prePos - 1);</span><br><span class="line">                 System.out.println(&quot;=====&quot; + offset);</span><br><span class="line">             &#125;</span><br><span class="line">             MappedByteBuffer mappedByteBuffer = fc.map(FileChannel.MapMode.READ_ONLY, prePos,</span><br><span class="line">                     offset);</span><br><span class="line">             bs = new byte[offset];</span><br><span class="line">             mappedByteBuffer.get(bs);</span><br><span class="line">             mappedByteBuffer.clear();</span><br><span class="line">             int start = 0;</span><br><span class="line">             for (int i = 0; i &lt; bs.length; i++) &#123;</span><br><span class="line">                 if (bs[i] == 10) &#123;</span><br><span class="line">                     byte[] toTemp = new byte[temp.length + i - start];</span><br><span class="line">                     System.arraycopy(temp, 0, toTemp, 0, temp.length);</span><br><span class="line">                     System.arraycopy(bs, start, toTemp, temp.length, i - start);</span><br><span class="line">                     start = i;</span><br><span class="line">                     temp = new byte[0];</span><br><span class="line">                     str = new String(toTemp);</span><br><span class="line">                     line++;</span><br><span class="line">                     if (line &gt;= 500000) &#123;</span><br><span class="line">                         throw new RuntimeException();</span><br><span class="line">                     &#125;</span><br><span class="line"></span><br><span class="line">                 &#125;</span><br><span class="line">             &#125;</span><br><span class="line">             //将最后不是一行的字符存起来下一次读取的时候用</span><br><span class="line">             if (start &lt; bs.length - 1) &#123;</span><br><span class="line">                 temp = new byte[bs.length - 1 - start];</span><br><span class="line">                 System.arraycopy(bs, start, temp, 0, bs.length - 1 - start);</span><br><span class="line">             &#125;</span><br><span class="line">         &#125;</span><br><span class="line">         long t2 = System.currentTimeMillis();</span><br><span class="line">         System.out.println(&quot;\n&quot; + (t2 - t1));</span><br></pre></td></tr></table></figure>
<p>-Xmx2048m -Xms2048m<br>无论怎么调缓冲区大小,最快是800000时需要两百多秒读完<br>可能是因为得重复将文件映射到内存里</p>
<p>但是,换了个200m的文件,mappedBuffer 一次读fc.size()时1.7秒 ;一次读10000左右时最快1.5秒<br>bufferredReader.readline():  1.4~1.7秒<br>python 1秒! 偶尔2秒</p>
<hr>
<p>###Tips:</p>
<p>1.python 的 str in list 数据量大时比较慢</p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>这两个图片是什么?可以扫吗?</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatPay.png" alt="Shen 微信支付">
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/aliPay.png" alt="Shen 支付宝">
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Java/" rel="tag"># Java</a>
          
            <a href="/tags/python/" rel="tag"># python</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/05/28/JVM/" rel="next" title="JVM">
                <i class="fa fa-chevron-left"></i> JVM
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/05/28/KCP协议/" rel="prev" title="KCP协议">
                KCP协议 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC80MjA1OS8xODYwNg=="></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
      <div id="sidebar-dimmer"></div>
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/saiki.jpeg" alt="Shen">
            
              <p class="site-author-name" itemprop="name">Shen</p>
              <p class="site-description motion-element" itemprop="description">Penn's blog</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">117</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">26</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-循环"><span class="nav-number">1.</span> <span class="nav-text">1.循环</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-循环处理字符串-循环次数少个0"><span class="nav-number">2.</span> <span class="nav-text">2.循环处理字符串(循环次数少个0)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-读取文件"><span class="nav-number">3.</span> <span class="nav-text">3.读取文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-NIO-MappedBuffer"><span class="nav-number">4.</span> <span class="nav-text">4.NIO MappedBuffer</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Shen</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  












  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("Gst71Gv0w5HKejm5H7LuG0XI-gzGzoHsz", "aoFAyHFDKihGTWWhHX0p8byC");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  

  

  

  

</body>
</html>
